import { getwarehouse, getbrand, getModelNumber } from '@/api/system/search.js'


const user = {
    namespaced: true,
    state: {
        warehouseList: [],//仓库
        brandList: [],//品牌
        ModelNumberList: [],//型号
        filterObj: {}
    },
    mutations: {
        CHANGE_STATE: (state, { key, arr, obj }) => {
            state[key] = [obj, ...arr]
        },
        CHANGE_FILTER: (state, obj) => {
            state.filterObj = obj
        },
    },
    actions: {
        getWarehouseAction({ commit, state }) {
            getwarehouse().then(res => {
                commit('CHANGE_STATE', { key: 'warehouseList', arr: res?.result || [], obj: { id: null, name: '全部' } })
            })
        },
        getBrandAction({ commit, state }) {
            getbrand().then(res => {
                commit('CHANGE_STATE', { key: 'brandList', arr: res?.result || [], obj: { id: null, name: '全部' } })

            })
        },
        getModelNumberAction({ commit, state }, str) {
            getModelNumber(str).then(res => {
                commit('CHANGE_STATE', { key: 'ModelNumberList', arr: res?.result || [], obj: { id: null, title: '全部' } })
            })
        }
    }
}

export default user
